package com.qys.livesMall.app.user.controller.sys;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.app.user.model.entity.SysInviteRewards;
import com.qys.livesMall.app.user.service.SysInviteRewardsService;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.framework.view.BaseQuery;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 邀请奖励配置表(SysInviteRewards)表控制层
 *
 * @author makejava
 * @since 2023-07-01 11:34:29
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/sysInviteRewards")
@Tag(name = "sys-邀请奖励配置管理", description = "邀请奖励配置管理")
public class SysInviteRewardsController {


    private final SysInviteRewardsService sysInviteRewardsService;

    /**
     * 分页查询所有数据
     *
     * @param dto 分页对象
     * @return 所有数据
     */
    @PostMapping("/selectAll")
    public R<IPage<SysInviteRewards>> selectAll(@RequestBody BaseQuery dto) {
        Page<SysInviteRewards> page = sysInviteRewardsService.page(new Page<>(dto.getPageNum(), dto.getPageSize()), Wrappers.query());
        return R.ok(page);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/getById")
    public R<SysInviteRewards> selectOne(@RequestParam Serializable id) {
        return R.ok(this.sysInviteRewardsService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param sysInviteRewards 实体对象
     * @return 新增结果
     */
    @PostMapping("/add")
    public R<?> insert(@RequestBody SysInviteRewards sysInviteRewards) {
        sysInviteRewardsService.save(sysInviteRewards);
        return R.ok();
    }

    /**
     * 修改数据
     *
     * @param sysInviteRewards 实体对象
     * @return 修改结果
     */
    @PostMapping("/update")
    public R<?> update(@RequestBody SysInviteRewards sysInviteRewards) {
        sysInviteRewardsService.updateById(sysInviteRewards);
        return R.ok();
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @PostMapping("/delete")
    public R<?> delete(@RequestBody List<Long> idList) {
        sysInviteRewardsService.removeByIds(idList);
        return R.ok();
    }
}

